package mysql

import (
	"database/sql"
	"web-app/models"
	"go.uber.org/zap"
)

func GetCommunityList() (communityList []*models.Community, err error) {
	sqlStr := "select community_id,community_name from community"
	err = db.Select(&communityList, sqlStr)
	if err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("there is no community in db")
			err = nil
		}
	}
	return
}

// 查询分类社区详情
func GetCommunityDetailByID(id int64) (communityDetailList *models.CommunityDetail, err error) {
	communityDetailList=new(models.CommunityDetail)
	sqlStr := "select community_id,community_name,introduction,create_time from community where community_id=?"
	err = db.Get(communityDetailList, sqlStr, id)
	if err != nil {
		if err == sql.ErrNoRows {
			zap.L().Warn("there is no community in db")
			err = nil
		}
	}
	return
}
